using QFramework.Framework.ResKit;
using UnityEditor;
using UnityEngine;

namespace QFramework.Example._9.ResMgrExample
{
    public class UIXXXPanel : MonoBehaviour
    {
        private ResLoader _resLoader = new();

        // Start is called before the first frame update
        private void Start()
        {
            _resLoader.LoadSync<AudioClip>("resources://Hit");
            _resLoader.LoadSync<AudioClip>("resources://Start");

            OtherFunction();
        }

        private void OnDestroy()
        {
            _resLoader.ReleaseAll();
            _resLoader = null;
        }

        private void OtherFunction()
        {
            _resLoader.LoadSync<AudioClip>("resources://Hit");
        }

#if UNITY_EDITOR
        [MenuItem("QFramework/Example/9.UIXXXPanel", false, 9)]
        private static void MenuClicked()
        {
            EditorApplication.isPlaying = true;

            new GameObject("UIXXXPanel")
                .AddComponent<UIXXXPanel>()
                .gameObject.AddComponent<UIYYYPanel>();
        }
#endif
    }

    public class UIYYYPanel : MonoBehaviour
    {
        private ResLoader _resLoader = new();

        // Start is called before the first frame update
        private void Start()
        {
            _resLoader.LoadSync<AudioClip>("resources://Hit");
            _resLoader.LoadSync<AudioClip>("resources://Start");

            OtherFunction();
        }

        private void OnDestroy()
        {
            _resLoader.ReleaseAll();
            _resLoader = null;
        }

        private void OtherFunction()
        {
            _resLoader.LoadSync<AudioClip>("resources://Hit");
        }
    }
}